package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Room;
import cn.wolfcode.trip.base.mapper.RoomMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.RoomQuery;
import cn.wolfcode.trip.base.service.IRoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements IRoomService{
    @Autowired
    private RoomMapper roomMapper;

    @Override
    public PageInfo queryForList(RoomQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Room> list = roomMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Room room) {
        if (room.getId()==null){
            room.setType(1); //未入住
            roomMapper.insert(room);  //新增
        }else {
            room.setType(0); //已入住
            roomMapper.updateByPrimaryKey(room);  //编辑
        }
    }

    /**
     * 根据roomID 获取对象
     * @param roomId
     * @return
     */
    @Override
    public Room queryByRoomId(Long roomId) {
        return roomMapper.selectByPrimaryKey(roomId);
    }

}
